import time
from datetime import datetime
from django.utils import timezone


def time_str(format: str = '%Y-%m-%d %H:%M:%S'):
    """获取当前时间字符串"""
    t = time.time()
    return time.strftime(format, time.localtime(t))


def localtime_str():
    """获取当前时间字符串"""
    t = timezone.localtime()
    return "%d-%02d-%02d %02d:%02d:%02d" % (t.year, t.month, t.day, t.hour, t.minute, t.second)


def get_date(date_str: str, format: str = '%Y-%m-%d %H:%M:%S'):
    """获取时间对象"""
    return datetime.strptime(date_str, format)